package cn.softwin.service.impl;

import cn.softwin.dao.CustumerDao;
import cn.softwin.dao.impl.CustumerDaoImpl;
import cn.softwin.domain.PageBean;
import cn.softwin.pojo.CstCustomer;
import cn.softwin.pojo.CstCustomerDetail;
import cn.softwin.service.CustumerService;

import java.util.List;

public class CustumerServiceImpl implements CustumerService {

    private CustumerDao custumerDao=new CustumerDaoImpl();


    /**
     * Description: 插入客户信息，返回布尔值
     * Author: zhangxiangkai
     * Params: [cstCustomer]
     * ReturnType: boolean
     * Time: 2021/2/17-17:00
     */
    @Override
    public boolean addCustumerMessage(CstCustomer cstCustomer) {
        return custumerDao.addCustumer(cstCustomer);
    }

    /**
     * Description: 插入客户详细信息，返回布尔值
     * Author: zhangxiangkai
     * Params: [cstCustomerDetail]
     * ReturnType: boolean
     * Time: 2021/2/17-23:40
     */
    @Override
    public boolean addCustumerDetailMessage(CstCustomerDetail cstCustomerDetail) {
        return custumerDao.addCustumerDetails(cstCustomerDetail);
    }


    /**
     * Description: 实现分页查询客户信息的功能
     * Author: zhangxiangkai
     * Params: [currentString, rowString]
     * ReturnType: cn.softwin.domain.PageBean<cn.softwin.pojo.CstCustomer>
     * Time: 2021/2/18-10:25
     */
    @Override
    public PageBean<CstCustomer> selectByPage(int currentPage, int rows) {
		//1.String接收  转int
//		int currentpage = Integer.parseInt(_currentPage);
//		int rows = Integer.parseInt(_rows);
		//2.创建PageBean对象
		PageBean<CstCustomer> pageBean = new PageBean<>();
		//3.设置参数 int
		pageBean.setCurrentpage(currentPage);
		pageBean.setRows(rows);
		//4.计算数据库开始索引
		int start=(currentPage-1)*rows;
		//5.调用dao查询每页数据，传入集合
		List<CstCustomer> selectByPage = custumerDao.selectByPage(start, rows);
		pageBean.setList(selectByPage);
		//6.调用dao查询总行数  赋值
		int selectTotalCount = custumerDao.selectTotalCount();
		pageBean.setTotalcount(selectTotalCount);
		//7.计算总页码  赋值
		int totalpage=(selectTotalCount%rows)==0?selectTotalCount/rows:(selectTotalCount/rows)+1;
		pageBean.setTotalpage(totalpage);

		return pageBean;
    }

    /**
     * Description: 根据id删除对应的客户信息
     * Author: zhangxiangkai
     * Params: [custId]
     * ReturnType: boolean
     * Time: 2021/2/18-17:26
     */
    @Override
    public boolean DeleteCustomerById(Long custId) {
        return custumerDao.deleteCustomerById(custId);
    }

    /**
     * Description:
     * Author: zhangxiangkai
     * Params: [custId]
     * ReturnType: cn.softwin.pojo.CstCustomerDetail
     * Time: 2021/2/18-19:40
     */
    @Override
    public CstCustomerDetail queryCustomerDetailsById(Long custId) {
        return custumerDao.queryCustomerDetailsById(custId);
    }

    /**
     * Description: 根据id查询客户信息
     * Author: zhangxiangkai
     * Params: [custId]
     * ReturnType: cn.softwin.pojo.CstCustomer
     * Time: 2021/2/18-21:39
     */
    @Override
    public CstCustomer queryCustomerById(Long custId) {
        return custumerDao.queryCustomerById(custId);
    }

    /**
     * Description: 根据id对客户信息进行修改
     * Author: zhangxiangkai
     * Params: [custId]
     * ReturnType: boolean
     * Time: 2021/2/18-21:40
     */
    @Override
    public Boolean updateCustomerById(CstCustomer cstCustomer) {
        return custumerDao.updateCustomerById(cstCustomer);
    }

    /**
     * Description: 根据id对客户详细信息进行修改
     * Author: zhangxiangkai
     * Params: [custId]
     * ReturnType: java.lang.Boolean
     * Time: 2021/2/18-21:42
     */
    @Override
    public Boolean updateCustomerDetailById(CstCustomerDetail cstCustomerDetail) {
        return custumerDao.updateCustomerDetailById(cstCustomerDetail);
    }


}
